import sys
from PySide6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
from PySide6.QtCore import QTimer, Qt
from PySide6.QtGui import QFont

class AutoDismissLabel(QWidget):
    def __init__(self, text, duration=1000):
        super().__init__()
        self.label = QLabel(text)
        self.label.setAlignment(Qt.AlignCenter)
        font = QFont()
        font.setPointSize(12)
        self.label.setFont(font)
        layout = QVBoxLayout()
        layout.addWidget(self.label)
        self.setLayout(layout)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)  # 无边框，置顶显示
        self.show()
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.close)
        self.timer.start(duration)  # 设置自动消失时间

app = QApplication(sys.argv)
auto_dismiss_label = AutoDismissLabel("这是一个自动消失的信息")
sys.exit(app.exec_())